<include file="Common:header" />
<TYimport plugin='datepicker' />
<style>
.sn_setPrice{padding:10px;}
.check{padding:3px 5px;}
.fl{float:left;}
.cl{clear:both;}
</style>
<div class="table_content" >
    <form enctype="multipart/form-data" id="upForm" class="ajax_form">
        <table class="edit_table">
            <tr>
                <td class="tablehead">洗車點名：</td>
                <td>
                    <input type="text" name="name" class="text w150 required" value="{$info.address_name}" style="width:200px;"/><label class="tips"></label>
                </td>
            </tr>
            <tr>
                <td class="tablehead">詳細地址：</td>
                <td>
                    <input type="text" name="location" class="text w150 required" value="{$info.location}" style="width:200px;"/><label class="tips"></label>
                </td>
            </tr>
            <tr>
                <td class="tablehead">服務電話：</td>
                <td>
                    <input type="text" name="address_phone" class="text w150 required" value="{$info.address_phone}" style="width:200px;"/><label class="tips"></label>
                </td>
            </tr>
             <tr>
                <td class="tablehead">營業時間：</td>
                <td>
                	開始時間：<input type="text" class="text w150" name="start_time" value='{$info[server_start_time]}' onClick="WdatePicker({dateFmt:'HH:mm'})"/>&nbsp;&nbsp;&nbsp;&nbsp;
            	        結束時間：<input type="text" class="text w150"  name="end_time"  value='{$info[server_end_time]}' onClick="WdatePicker({dateFmt:'HH:mm'})" /></td>

                </td>
            </tr>
			<tr>
                <td class="tablehead">下單間隔時間：</td>
                <td>
            	       <input type="text" class="text w50"  name="time_interval"  value='{$info[time_interval]}'/>分鐘</td>
                </td>
            </tr>
            <tr>
                <td class="tablehead">同一時間段可接收的下單量：</td>
                <td>
                	<input type="text" class="text w50" name="meanwhile_order" value='{$info[meanwhile_order]}'/>個
                </td>
            </tr>
			<tr>
                <td class="tablehead">圖片</td>
                <td>
                    <img src="{$info.address_img}" id="shop_img" name="shop_img" style="width:200px;"/><br/>

                    <input type="button" class="up" value="上傳新圖片" style="padding:10px;margin-top:10px;"/>
                    <input type="file" id="upload_shopImg" name="upload_shopImg"  onchange="showPicture(this)" style="display:none;"/>
                </td>
            </tr>

			<script type="text/javascript">
			$('.up').click(function(){
				$('#upload_shopImg').click();
			});
			function showPicture(imgFile){
				var picURL = window.URL.createObjectURL(imgFile.files[0]);
				document.getElementById("shop_img").src = picURL;
				$('#upload_shopImg').val(picURL);
			}
			</script>

			<tr>
				<td class="tablehead">服務</td>
				<td>
					<foreach name="list" item="vo">
						<div class="check fl"><input type="checkbox" server_name_id="{$vo.id}" server_name="{$vo.server_name}"/>{$vo.server_name}</div>
					</foreach>
					<div class="cl"></div>

						<foreach name="list" item="vo">
						<div class='sn_id_{$vo.id} sn_setPrice fl' <if condition="$vo['check'] eq 0">style="display:none;"</if>>
							服務名：{$vo.server_name}
							<br/>五座車：<input type='text' value="{$vo['price']['five_price']}" name='five_sn_price_{$vo.id}' class='text w50 required'/>元
							<br/>七座車：<input type='text' value="{$vo['price']['seven_price']}" name='seven_sn_price_{$vo.id}' class='text w50 required'/>元
							<br/>其他車：<input type='text' value="{$vo['price']['other_price']}" name='other_sn_price_{$vo.id}' class='text w50 required'/>元
						</div>
						</foreach>

					<div class="setPrice"></div>
				</td>
			</tr>

            <tr>
                <td class="tablehead">溫馨提示</td>
                <td>
                	<textarea class="shop_tips" name="tips" style="width:300px;height:200px;">{$info.tips}</textarea>
                    <label class="tips">洗車點詳情展示</label>
                </td>
            </tr>
            <tr>
                <td class="tablehead">狀態</td>
                <td>
                    <span class="radio">
                        <input type="radio" id="radio2" name="status" value="1" <?php echo $info['status']== 1 ? checked:'' ?>/><label for="radio2">休憩</label>
                        <input type="radio" id="radio3" name="status" value="2" <?php echo $info['status']== 2 ? checked:'' ?>/><label for="radio3">忙碌</label>
                        <input type="radio" id="radio4" name="status" value="3" <?php echo $info['status']== 3 ? checked:'' ?>/><label for="radio4">空閒</label>
                    </span>
                </td>
            </tr>
            <tr>
                <td class="tablehead">操作</td>
                <td>
                	<input type="hidden" name="server_id" value="{$_GET['id']}"/>
                	<input type="hidden" name="server_name_id" value=""/>
                	<if condition="$type eq add">
                		<input type="hidden" name="action" value="add"/>
                		<input type="button" class="add_btn" value="添加"/>
                	<else/>
                		<input type="hidden" name="action" value="edit"/>
                		<input type="button" class="save_btn" value="保存"/>
                	</if>
                    <input type="button" class="back_btn" value="返回"/>
                </td>
            </tr>
        </table>
    </form>
</div>
<script type="text/javascript">
<foreach name="price" item="v">
$('input[server_name_id='+{$v.server_name_id}+']').attr('checked',true);
</foreach>

$('input[type=checkbox]').click(function(){
	var server_name = $(this).attr('server_name');
	var server_name_id = $(this).attr('server_name_id');
	if($(this).prop('checked')){
		$(this).attr('checked',true);
		$('.sn_id_'+server_name_id).show();
	}else{
		$('.sn_id_'+server_name_id).hide();
		$(this).attr('checked',false);
	}
});
</script>
<script type="text/javascript">
$('.add_new_address').click(function(){
	var html = "<tr>";
		html += "<td class='tablehead'>新增地址：</td>";
		html += "<td>";
		html +=     "<input type='text' name='address_name[]' class='text w150 required' style='width:300px;'/>";
		html += "</td>";
		html += "</tr>";
	$('.server_tel').before(html);
});

$('.delete_address').click(function(){
	var addressId = $(this).next('input[name=delete_address]').attr('addressId');
	art.dialog({
        id: 'confirm',
        title: '消息',
        icon: 'question',
        opacity: .1,
        resize: false,
        lock: true,
        fixed: true,
        content: '你確定要刪除此地址？',
        button: [
            {
                name: '确定',
                callback: function() {
                    this.close();

                	$.ajax({
                        url: "{:U(MODULE_NAME.'/'.CONTROLLER_NAME.'/delete_address')}" ,
                        type: 'POST',
                        dataType: 'json',
                        data : {addressId : addressId},
                        success: function (returndata) {
                       		if(returndata.status){
                       			alert(returndata.info);
                       		 /* callBackTips(returndata.status,returndata.info); */
                       			window.location.href = window.location.href;
                    		}else{
                    			callBackTips(0,returndata.info);
                    		}
                        },
                   });
                    return false;
                },
                focus: true
            },
            {
                name: '取消'
            }
        ]
    });

});
$('.add_btn').click(function(){
	var server_name_id = '';
	$('input[type=checkbox]').each(function(){
		if($(this).prop('checked')){
			server_name_id = $(this).attr('server_name_id') + ',' + server_name_id;
		}
	});
	$('input[name=server_name_id]').val(server_name_id);
	var formData = new FormData($( "#upForm" )[0]);
	$.ajax({
        url: "{:U(MODULE_NAME.'/'.CONTROLLER_NAME.'/add_address')}" ,
        type: 'POST',
        data : formData,
        async: false,
        cache: false,
        contentType: false,
        processData: false,
        success: function (returndata) {
       	if(returndata.status){
       		 callBackTips(returndata.status,returndata.info,returndata.url);
    		}else{
    			callBackTips(0,returndata.info);
    		}
        },
   });
});

$('.save_btn').click(function(){
	var server_name_id = '';
	$('input[type=checkbox]').each(function(){
		if($(this).prop('checked')){
			server_name_id = $(this).attr('server_name_id') + ',' + server_name_id;
		}
	});
	$('input[name=server_name_id]').val(server_name_id);
	var formData = new FormData($( "#upForm" )[0]);
    $.ajax({
         url: "{:U(MODULE_NAME.'/'.CONTROLLER_NAME.'/add_address')}" ,
         type: 'POST',
         data : formData,
         async: false,
         cache: false,
         contentType: false,
         processData: false,
         success: function (returndata) {
        	if(returndata.status){
        		 callBackTips(returndata.status,returndata.info,returndata.url);
     		}else{
     			callBackTips(0,returndata.info);
     		}
         },
    });
});
</script>
<include file="Common:footer" />
